home *** CD-ROM | disk | FTP | other *** search
- Path: news.eznet.net!usenet
- From: Joe Mihalich <mihalich@eznet.net>
- Newsgroups: comp.lang.c++
- Subject: VC++ 4.0 and Templates and the Compiler
- Date: Sat, 27 Jan 1996 14:26:12 -0500
- Organization: E-Znet Inc. Rochester N.Y. 14623 (716)-262-2485
- Message-ID: <310A7C54.4518@eznet.net>
- NNTP-Posting-Host: dialin-03.eznet.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (WinNT; I)
-
- Hi,
-
- Anyone who can answer this question will be the hero of
- the year. I am using Visual C++ 4.0 on both WIN NT and WIN 95.
-
- I have defined a class template that is derived from the
- MFC class CString. The class template is defined in a DLL.
- In order for ALL of the functions to be exported properly,
- they have to be instantiated via the compiler.
-
- Now, not all of the functions are being called from within
- the DLL, so the compiler is not instantiating them, which
- is not allowing me to call those functions from another
- DLL or APP.
-
- Microsoft provides 3 ways of solving this problem:
-
- 1) Declare/Define all functions in your class or it's
- .h file. All functions defined there are considered
- inline and are automatically instantiated. For
- example:
-
- //MyString.h
-
- template <class TYPE> class CMyString : public CString
- {
- TYPE Left(int nStart)
- { return (TYPE)CString::Left(nStart); }
- TYPE Left(int nStart, int nCount)
- { return (TYPE)CString::Left(nStart, nCount); }
- };
-
- This is the ideal method for me to use, but it DOES NOT
- WORK. All of my functions are defined in the .h files
- cuz there not doing anything but calling the base class
- functions. The only functions that get instantiated are
- the ones that are called from within the DLL. I can verify
- this via the .MAP file.
-
- 2) In the source file where the functions are defined, reference
- the function somewhere by taking it's address. I tried this,
- but couldn't get it to work either. This method I probably
- screwed up, cuz I didn't know how to get the address of a function
- when there were multiple overloaded versions of the function.
- Any suggestions of how to do this? For example:
-
- //MyString.h
-
- template <class TYPE> class CMyString : public CString
- {
- TYPE Left(int nStart)
- { return (TYPE)CString::Left(nStart); }
- TYPE Left(int nStart, int nCount)
- { return (TYPE)CString::Left(nStart, nCount); }
- void Dummy(void);
- };
-
- Now, how do I take the address of either of the LEFT functions?
-
- //MyString.cpp
-
- CMyString::Dummy(void)
- {
- pFunction1 = &this->Left(int nStart);
- pFunction2 = &this->Left(int nStart, int nCount);
- }
-
- Is that correct? If it is, than this method did not work
- for me either!
-
- 3) Create a dummy function in your base class that calls all
- functions. The dummy function does not need to be
- called by anyone. For Example:
-
- CMyString::Dummy(void)
- {
- this->Left(0);
- this->Left(0,0);
- }
-
- Unfortunately this is the only method that worked for me. I consider
- this to be an unacceptable solution because it just seems ludicrous
- to have to do it this way.
-
-
- If anyone has any ideas on how to make the first solution work, I
- would appreciate it. I am assuming that there is some stupid
- compiler option that is turning off the expansion of inline
- functions or something. (Bye the way, I tried fooling around with
- the compiler option in (C/C++ - Optimizations in the build settings
- dialog) called "Inline function expansion". The possible options
- are: disabled, Inline Functions, Any suitable function. For debug
- mode, this option is always set to disabled. I tried setting it
- to either of the other two, but it didn't change anything. The help
- says that this option is just a suggestion to the compiler anyway.
-
- Any help will be greatly appreciated.
-
- Thanks,
- Joe Mihalich
-
- --
- Joe Mihalich
- Email: mihalich@eznet.net
- Voice: 716-482-0089
-